package com.serialcommunication.gui.component;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.text.MaskFormatter;

import com.serialcommunication.enums.Engine;
import com.serialcommunication.gui.frame.MainFrame;
import com.serialcommunication.interfaces.IAction;
import com.serialcommunication.interfaces.IBaseComponent;
import com.serialcommunication.interfaces.ITransmitComponent;

import static com.serialcommunication.constants.GuiConfiguration.*;

public class TextFieldReadOnlyResetOptionComponent extends BaseComponent implements ITransmitComponent {

	private JButton signButton;
	private JButton setButton;

	private JLabel label;
	private JFormattedTextField textField;

	public TextFieldReadOnlyResetOptionComponent(Engine pEngine, IAction pAction, MainFrame pFrame, MaskFormatter pFormatter, int pMax, int pMin,
			int valueBytes) {
		super(pEngine, pAction, pFrame);
		
		getPanel().setLayout(null);
		getPanel().setBackground(new Color(234, 237, 241));
		getPanel().setBorder(BorderFactory.createLineBorder(new Color(179, 181, 184)));
		
		signButton = new JButton("+");
		setButton = new JButton("SNR");
		label = new JLabel(pAction.getTitle());
		textField = new JFormattedTextField(pFormatter);
		
		signButton.setBorder(null);
		setButton.setBorder(null);
		
		label.setFont(new Font(Font.DIALOG, Font.PLAIN, 10));
		textField.setFont(new Font(Font.DIALOG, Font.PLAIN, 10));
		setButton.setFont(new Font(Font.DIALOG, Font.PLAIN, 10));

		addComponentsToPanel();
		setSizeOfElementsAndPanel();
		alignElementsWithinPanel();
		initListener();
		disableComponent();
	}

	public void addComponentsToPanel() {
		getPanel().add(signButton);
		getPanel().add(setButton);
		getPanel().add(label);
		getPanel().add(textField);
	}

	public void setSizeOfElementsAndPanel() {
		getPanel().setSize(PANEL_TEXTFIELDREADONLY_1);
		signButton.setSize(BUTTON_SIGN_SIZE);
		setButton.setSize(BUTTON_SNR_SIZE);
		label.setSize(LABEL_SIZE);
		textField.setSize(TEXTFIELD_SIZE_3);
		
	}

	public void alignElementsWithinPanel() {
		label.setLocation(PANEL_ELEMENT_PADDING_X, PANEL_ELEMENT_PADDING_Y);
		signButton.setLocation(PANEL_ELEMENT_PADDING_X, PANEL_ELEMENT_PADDING_Y + label.getHeight());
		textField.setLocation(PANEL_ELEMENT_PADDING_X + signButton.getWidth(), PANEL_ELEMENT_PADDING_Y + label.getHeight());
		setButton.setLocation(PANEL_ELEMENT_PADDING_X + signButton.getWidth() + textField.getWidth(), PANEL_ELEMENT_PADDING_Y + label.getHeight());
	}

	public void initListener() {

	}

	@Override
	public void setValue(String pValue) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getValue() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void transmitData() {
		// TODO Auto-generated method stub

	}

	@Override
	public void disableComponent() {
		signButton.setEnabled(false);
		setButton.setEnabled(false);
		textField.setEnabled(false);
		label.setEnabled(false);
	}

	@Override
	public void enableComponent() {
		signButton.setEnabled(true);
		setButton.setEnabled(true);
		textField.setEnabled(true);
		label.setEnabled(true);
	}
	
	@Override
	public void setInActive() {
		// not needed
	}

	@Override
	public void setActive() {
		// not needed
	}

}
